package com.ld.security.server.admin.modules.gl.api;

import com.ld.security.common.mybatis.base.po.IdPo;
import com.ld.security.common.tomcat.anno.AjaxLogKey;
import com.ld.security.server.admin.modules.gl.entity.GlEnumEntity;
import com.ld.security.server.admin.modules.gl.po.CodePo;
import com.ld.security.server.admin.modules.gl.po.EnumDetailsPo;
import com.ld.security.server.admin.modules.gl.po.EnumSavePo;
import com.ld.security.server.admin.modules.gl.service.IGlEnumItemService;
import com.ld.security.server.admin.modules.gl.service.IGlEnumService;
import com.ld.security.server.admin.modules.gl.vo.EnumDetailsVo;
import com.ld.security.common.mybatis.base.po.IdsPo;
import com.ld.security.common.mybatis.base.po.ListPo;
import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.common.mybatis.base.vo.ListVo;
import com.ld.security.common.tomcat.base.api.SuperApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@Api(tags="全局字典Api管理")
@RequestMapping("/api/glEnum")
public class GlEnumApi  extends SuperApi<GlEnumEntity> {

        @Autowired
        IGlEnumService iGlEnumService;
        @Autowired
        IGlEnumItemService iGlEnumItemService;

//        @AjaxLogKey
//        @ApiOperation("删除枚举项")
//        @RequestMapping(value = "/deleteEnumItem",method =RequestMethod.POST)
//        public DataVo deleteEnumItem(@RequestBody IdsPo po){
//                int total = iGlEnumItemService.removeByIds(po.getIds());
//                return DataVo.ofMsg("删除"+total+"条数据");
//        }

        @AjaxLogKey
        @ApiOperation("根据编码查询字典")
        @RequestMapping(value = "/getEnumDetails",method =RequestMethod.POST)
        public DataVo getEnumDetails(@RequestBody CodePo po){
                EnumDetailsVo vo =  iGlEnumService.getEnumDetails(po.getCode());
                return DataVo.of(vo);
        }
        @AjaxLogKey
        @ApiOperation("保存枚举集合")
        @RequestMapping(value = "/saveEnum",method =RequestMethod.POST)
        public DataVo saveEnum(@RequestBody EnumSavePo po){
                iGlEnumService.saveEnum(po);
                return DataVo.ofMsg("字典修改成功");
        }

        @AjaxLogKey
        @ApiOperation("根据父编码查询字典")
        @RequestMapping(value = "/findByParentEnum",method =RequestMethod.POST)
        public DataVo findByParentEnum(@RequestBody ListPo<CodePo> po){
                List<GlEnumEntity> es =  iGlEnumService.all(po.getQuery());
                return DataVo.of(ListVo.of(es));
        }


}
